﻿using System.ComponentModel;
using ZeroSum.App.Datas;
using ZeroSumZSA.Api.Apis;
using ZeroSumZSA.Application.ApplicationServices.Roles;
using ZeroSumZSA.Application.ApplicationServices.Roles.Dto.In;
using ZeroSumZSA.Application.ApplicationServices.Roles.Dto.Out;
using ZeroSumZSA.Application.ApplicationServices.Roles.Dto.Query;

namespace ZeroSumZSA.Api.Controllers;

/// <summary>
///     角色管理
/// </summary>
[Description("管理-角色管理")]
public class RoleController : AdminApiController
{
    private readonly IRoleApplicationService _service;

    /// <summary>
    ///     构造函数
    /// </summary>
    /// <param name="service"></param>
    public RoleController(IRoleApplicationService service)
    {
        _service = service;
    }

    /// <summary>
    ///     分页获取角色列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResponse<PagedResponseModel<PageRoleDto>>> Page([FromQuery] PageRoleQuery input)
    {
        var pageRoles = await _service.Page(input);
        return ApiResponse<PagedResponseModel<PageRoleDto>>.Of(pageRoles);
    }

    /// <summary>
    ///     增加角色
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Add([FromBody] AddRoleDto dto)
    {
        await _service.AddAsync(dto);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     删除角色
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Delete([FromBody] DeleteRoleDto dto)
    {
        await _service.DeleteAsync(dto);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     更新角色
    /// </summary>
    /// <param name="dto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Edit([FromBody] EditRoleDto dto)
    {
        await _service.UpdateAsync(dto);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     获取角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<ApiResponse<DetailRoleDto>> Detail([FromQuery] DetailRoleQuery input)
    {
        var detailRole = await _service.Detail(input);
        return ApiResponse<DetailRoleDto>.Of(detailRole);
    }
}